<template>
	<view class="padb20">
		<stop isBack>
			<view slot="content">职工信息</view>
		</stop>
		<view class="lh2 bcf pad2 bdtso mart3">
			<view class="list-style-2 flrc">
				<view class="flex1">基本信息</view>
			</view>
			<view class="lh2 bcf pad2 bdtda mart3">
				<stree label="责任部门" model="Department" placeholder="请选择" v-model="en.department"></stree>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stext label="工号" placeholder="请填工号" v-model="en.code"></stext>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stext label="姓名" placeholder="请填写真实姓名" v-model="en.name"></stext>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stext label="手机" placeholder="请填常用手机" v-model="en.phone"></stext>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stext label="性别" placeholder="请填性别" v-model="en.sex"></stext>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stext label="年龄" placeholder="请填年龄" v-model="en.age"></stext>
			</view>
		</view>
		
		<view class="lh2 bcf pad2 bdtso mart3">
			<view class="list-style-2 flrc">
				<view class="flex1">职工近期照片</view>
			</view>
			<view class="lh2 bcf pad2 mart3">
				<spic label="照片" placeholder="请选择" v-model="en.pic"></spic>
			</view>
		</view>
		
		<view class="lh2 bcf pad2 bdtso pos-f l0 r0 b0">
			<view class="tac pad2 line-green round cu-btn lg w100 mart5" @tap="submit">
				<view>提交</view>
				<ripple></ripple>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				en:{
					department:"",
					code:"",
					name:"",
					phone:"",
					sex:"",
					age:"",
					pic:"",
				}
			}
		},
		methods: {
			submit(){
				this.log(this.en)
				//检查数据
				if(this.isnull(this.en.department)){this.$com.showToast('请选择部门');return;}
				if(this.isnull(this.en.code)){this.$com.showToast('请输入工号');return;}
				if(this.isnull(this.en.name)){this.$com.showToast('请输入姓名');return;}
				if(this.isnull(this.en.phone)){this.$com.showToast('请输入手机号');return;}
				if(this.isnull(this.en.sex)){this.$com.showToast('请输入性别');return;}
				if(this.isnull(this.en.age)){this.$com.showToast('请输入年龄');return;}
				if(this.isnull(this.en.pic)){this.$com.showToast('请设置员工照片');return;}
				this.$api.put("/api/machineUsers",this.en,(res)=>{
					this.log(res)
					if(res.s == 1){
						this.goback() 
					}
				})
			}
		},
		onLoad(option) {
			this.id = option.id
			if(this.isbool(this.id)){
				this.showLoading()
				this.$api.res('machine_users',this.id,res=>{
					this.log(res)
					this.en = res
					this.clearLoading()
				})
			}else{
				setTimeout(()=>{
					this.clearLoading()
				},500)
			}
		},
		watch:{
			nums(va){
				this.log(va)
			}
		}
	}
</script>

<style>

</style>
